# -*- coding:utf-8 -*-
"""
@author: ksf

@since: 2020-04-26 11:05
"""
from vcat.core.template import BaseTemplate
from vcat.core.constant import (
    OrderType,
    DataLevel
)
from vcat.core.obj import (
    BarData,
    BarGenArrayParams
)


class BuySellStrategy(BaseTemplate):

    author = 'fsksf'

    gen_params_list = [
        BarGenArrayParams(bar_level=DataLevel.minute, bar_interval=1, arr_size=60),
    ]

    _count = 0

    def on_bar(self, bar: BarData):
        if bar.level == DataLevel.minute and bar.interval == 1:
            mod = self._count % 17
            if mod == 0:
                self.long(cid=bar.cid, price=bar.close_price, volume=200, order_type=OrderType.LMT)
            elif mod == 8:
                self.sell(cid=bar.cid, price=bar.close_price, volume=200, order_type=OrderType.LMT)

            self._count += 1

